﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using LGE;

namespace MagicFight
{
    public class ArcaneShot : Magic
    {
        int damage = Def.ArcaneShotDef.Damage;
        Projectile projectile = null;

        public ArcaneShot(Character caster)
            : base(caster, Def.ArcaneShotDef.N)
        {
        }

        public override void Effect(GameTime gameTime)
        {
            if (projectile == null)
                ps.gameObjects.Add(projectile = new Projectile(caster, Engine.Load<Texture2D>("Images\\Magic\\fireball"), 3));
            if (!projectile.alive) { alive = false; return; }
            if (!projectile.collided) return;
            
            // se chegou aqui significa aque acabou de colidir
            projectile.alive = false;
            alive = false;
            GameObject target = projectile.target;
            if (target is Character)
            {
                Character charTarget = (target as Character);
                int d = charTarget.TakeDamage(damage, caster);
                if (d > 0) ps.effectsManager.Add(new FloatingText(charTarget.position, d.ToString(), Color.Red));
                Log.Add(charTarget.name + " tomou " + d + " de dano do Arcane Shot do " + caster.name);
            }
        }
    }
}
